import instance from "@/main";
import quotationDict from "@/dict/quotation";
import orderDict from "@/dict/order";
import { getOrderDetail } from "@/api/order";
import { getlineorderdetail } from "@/api/order-line";
import storage from "@/util/storage";

// 跳转订单详情
export function checkOrderDetail(data) {
  getOrderDetail({
    orderId: data.businessId
  }).then(res => {
    storage.s_set("orderDetail", res);
    let routeName;
    let direction =
      res.businessDirection === orderDict.direction.buy.value
        ? "buyer"
        : "seller";
    let orderPriceType =
      res.priceType === quotationDict.priceType.confirm.value
        ? "ConfirmOrderDetail"
        : "PricingOrderDetail";
    routeName = direction + orderPriceType;
    instance.$router.push({
      name: routeName,
      query: {
        id: data.businessId
      }
    });
    instance.$store.dispatch("updateRefreshStatus");
  });
}

// 跳转线路订单详情
export function checkLineOrderDetail(data) {
  getlineorderdetail({
    id: data.businessId
  }).then(res => {
    storage.s_set("lineOrderDetail", res);
    let routeName;
    let direction =
      res.businessDirection === orderDict.direction.buy.value
        ? "buyer"
        : "seller";
    let orderPriceType =
      res.priceType === quotationDict.priceType.confirm.value
        ? "ConfirmLineOrderDetail"
        : "PricingLineOrderDetail";
    routeName = direction + orderPriceType;
    instance.$router.push({
      name: routeName,
      query: {
        id: data.businessId
      }
    });
    instance.$store.dispatch("updateRefreshStatus");
  });
}

// 获取消息弹窗开关状态
export function getMessageSwitchStatus() {
  let res;
  let switchStatus = instance.$storage.get("messageSwitch");
  // 没有存储消息开关标识，则默认打开
  if (switchStatus === null || switchStatus === undefined) {
    res = true;
  } else {
    res = switchStatus;
  }
  return res;
}
